import request from '@/router/axios'
import {systemUrls} from '@/const/apiUrl'
import {PROJECT_DIC,} from '@/const/dict'


/**
 *  根据类型获取字典
 */
export function getDictType(type) {
  return request({
    url: '/admin/dict/type/'+type,
    method: 'get',
  }).then((response) => { // 处理返回的文件流
  })
}



/**
 *  获取申报单位字典
 */
export const getOrgDic = (query,dataParam,self) => {
  return request({
    url: systemUrls.deptTree,
    method: 'get',
    params: query
  }).then((response) => { // 处理返回的文件流
    self[dataParam] = changeOrgCode(response.data.data,[])
  })
}

function changeOrgCode(orgList,orgDataList) {
  for(var i in orgList){
    var orgCodeMap = {
      label:orgList[i].name,
      value:orgList[i].id
    }
    orgDataList.push(orgCodeMap)
    if(orgList[i].children && orgList[i].children.length>0){
      changeOrgCode(orgList[i].children,orgDataList)
    }
  }
  return orgDataList;
}
